function [results_fnames results] = osl_run_first_level( oat )

% [results_fnames results] = osl_run_first_level( oat )
%
% takes in an OAT, which needs to be setup by calling oat=osl_setup_oat(S), struct
% and runs first level analysis
%
% This function should normally be called using osl_run_oat(oat);
%
% MWW 2011

global OSLDIR;

if(~oat.first_level.is_epoched),    

    switch lower(oat.source_recon.type)
        case 'scalar'
            if(~isempty(oat.first_level.connectivity_seed_mni_coord)),
                error('Scalar beamformer with continuous time seed based connectivity currently not supported');
            else
                [results_fnames results] = osl_run_first_level_continuous_state(oat); % Do time-wise analysis state-wise        

            end;
        case 'vector'   

            if(~isempty(oat.first_level.connectivity_seed_mni_coord)),
                [results_fnames results] = osl_run_first_level_continuous_state_vector_seed(oat); % Do time-wise analysis state-wise        
            else
                [results_fnames results] = osl_run_first_level_continuous_state_vector(oat); % Do time-wise analysis state-wise        
            end;
    end;

else
    
    if(isfield(oat.first_level,'connectivity_seed_mni_coord') && ~isempty(oat.first_level.connectivity_seed_mni_coord)),    
        error('Currently not supported');
        [results_fnames results] = osl_run_first_level_epoched_connectivity(oat); 
    else        
        [results_fnames results] = osl_run_first_level_epoched_state(oat); % Do time-wise analysis state-wise       
    end;
    
end;
